//
//  VoiceReadDetailCoverView.m
//  ShowYork
//
//  Created by hxh on 2021/4/20.
//  Copyright © 2021 hxh. All rights reserved.
//

#import "VoiceReadDetailCoverView.h"

@interface VoiceReadDetailCoverView ()
@property (nonatomic,strong)UIView *coverView;
@property (nonatomic,strong)UIImageView *bgImgView;
@property (nonatomic,strong)UIImageView *centerImgView;
@property (nonatomic,strong)UIView *line;
@property (nonatomic,strong)UILabel *titleLb;
@end

@implementation VoiceReadDetailCoverView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setUI];
    }
    return self;
}
- (void)setUI{
    

    self.frame = CGRectMake(0, 0, kScreenW, kScreenW/4*3 + 32);
    
    self.coverView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenW/4*3)];
    [self addSubview:self.coverView];

    self.bgImgView = [[UIImageView alloc]init];
    self.bgImgView.contentMode = UIViewContentModeScaleAspectFill;
    self.bgImgView.layer.masksToBounds = YES;
    self.bgImgView.frame = CGRectMake(0, 0, kScreenW, kScreenW/4*3);
    [self.coverView addSubview:self.bgImgView];
    UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];

    UIVisualEffectView *effectview = [[UIVisualEffectView alloc] initWithEffect:blur];

    effectview.frame = CGRectMake(0, 0, kScreenW, kScreenW/4*3);
    effectview.alpha = 1;
    [self.bgImgView addSubview:effectview];

    UIView *a = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenW/4*3)];

    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.frame = CGRectMake(0, 0, kScreenW, kScreenW/4 * 3);
    gradientLayer.startPoint = CGPointMake(0.5, 0);
    gradientLayer.endPoint = CGPointMake(0.5, 1);
    gradientLayer.colors = [NSArray arrayWithObjects:
    (id)[RGBA(255,255,255,0) CGColor],
    (id)[RGBA(255,255,255,1) CGColor],nil];

    [a.layer addSublayer:gradientLayer];

    [self.bgImgView addSubview:a];
    
    
    
    self.centerImgView = [[UIImageView alloc]init];
    self.centerImgView.contentMode = UIViewContentModeScaleAspectFill;
    self.centerImgView.layer.cornerRadius = 8;
    self.centerImgView.layer.masksToBounds = YES;
    [self addSubview:self.centerImgView];
    self.centerImgView.frame = CGRectMake(0, 0, KScaleWidth(110),KScaleWidth(110) /3 * 4);
    self.centerImgView.cl_y = kNavBarHeight;
    self.centerImgView.cl_centerX = self.cl_centerX;
    

    self.titleLb = [[UILabel alloc]initWithFrame:CGRectMake(15, CGRectGetMaxY(self.centerImgView.frame) + 20,kScreenW - 32,100)];
    self.titleLb.font = [UIFont boldSystemFontOfSize:18];
    self.titleLb.textColor = C51;
    self.titleLb.numberOfLines = 0;
    self.titleLb.textAlignment = NSTextAlignmentCenter;
    [self addSubview:self.titleLb];
    
    
    self.line = [[UIView alloc]initWithFrame:CGRectMake(16,CGRectGetMaxY(self.titleLb.frame) + 32, kScreenW - 32, 0.5)];
    self.line.backgroundColor = RGBA(230, 230, 230, 1);
    [self addSubview:self.line];
}
- (void)setDtlModel:(VoiceReadDetailItemModel *)dtlModel{
    
    _dtlModel = dtlModel;
    
    CGSize textSize = [RPAppManager getTextSizeWithText:dtlModel.title font:[UIFont boldSystemFontOfSize:18] maxSize:CGSizeMake(kScreenWidth - 32, MAXFLOAT)];
    
    self.titleLb.text = dtlModel.title;
   
    self.titleLb.cl_height = ceil(textSize.height);
    
    self.line.cl_y = CGRectGetMaxY(self.titleLb.frame) + 32;
    
    [self.bgImgView sd_setImageWithURL:[NSURL URLWithString:dtlModel.coverLog]];
   
    [self.centerImgView sd_setImageWithURL:[NSURL URLWithString:dtlModel.coverLog]];
    
}

@end
